<?php

if (!$l_loged) {
    include "login_error.php";
} else { if ($l_role < 0) {
        include "role_error.php";
    } else {
        ?>
<h2 class="cont_page">Změna hesla</h2>

<?PHP
if (isset($_POST['pass_btn']) && (($_POST['pass'] != '') && ($_POST['pass_old'] != '') && ($_POST['pass_rep'] != ''))) {
    if (user_load_value("pass") != hash("md5", $_POST['pass_old']) ) {
        echo('<p class="err_desc">Zadali jste neplatné heslo!!</p>');
    } else {
        if ($_POST['pass'] == $_POST['pass_rep']) {
            if (user_change_pass($_POST['pass_old'], $_POST['pass'])) {
                echo('<p class="ok_desc">Heslo bylo změněno..</p><br><br>');
            } else {
                echo ('<p class="err_desc">Chyba při vkládání !!</p>');
            }
        }
    }
}
include "dom.html"; 
?>

<form action="passwd.php" method="post" id="form_pass" name="form_pass">
    <fieldset  class="pass">
        <legend>Změna hesla - <?PHP echo($_SESSION['username']); ?></legend>
        <p <?PHP if (isset($_POST['pass_btn']) && ($_POST['pass_old'] == '')) {echo ('class="err_form"');} else {echo ('class="err_form"');} ?>>
            <label for="pass_old" class="nes">*Heslo staré:</label>
            <input type="password" maxlength="50" value="" id="pass_old" name="pass_old" onfocus="info('Zadejte stare heslo..')">
        </p>

        <p <?PHP if (isset($_POST['pass_btn']) && ($_POST['pass'] == '')) {echo ('class="err_form"');} else {echo ('class="err_form"');} ?>>
            <label for="pass" class="nes">*Heslo nové:&nbsp;</label>
            <input type="password" maxlength="50" value="" id="pass" name="pass" onfocus="info('Zadejte nove heslo..')">
        </p>

        <p <?PHP if (isset($_POST['pass_btn']) && ($_POST['pass_rep'] == '')) {echo ('class="err_form"');} else {echo ('class="err_form"');} ?>>
            <label for="pass_rep" class="nes">*Heslo znovu:</label>
            <input type="password" maxlength="50" value="" id="pass_rep" name="pass_rep" onfocus="info('Zadejte znovu nove heslo..')">
        </p>
       <?PHP if (isset($_POST['pass_btn']) && (($_POST['pass'] == '') || ($_POST['pass_old'] == '') || ($_POST['pass_rep'] == ''))) {echo ('<p class="err_desc">* Všechny prvky touto barvou je nutné vyplnit!</p>');}
            if (isset($_POST['pass_btn']) && (($_POST['pass'] != $_POST['pass_rep']))){
                echo ('<p class="err_desc">* Nová hesla musí být stejná!!</p>');
            }
            ?>
    <p>
        <input class="btn" type="submit" value="Změnit" id="pass_btn" name="pass_btn">
    </p>
    </fieldset>


</form>

<script type="text/javascript">
    var form = document.getElementById('form_pass');
    form.onsubmit = ctrl_usr;

    function ctrl_usr(){
        var pass_old = document.getElementById('pass_old');
        var pass = document.getElementById('pass');
        var pass_rep = document.getElementById('pass_rep');

        if (pass_old.value == ''){
            alert('Chybí vypln\u011bné staré heslo!');
            return(true);
        }
        if (pass.value == ''){
            alert('Chybí vypln\u011bné heslo!');
            return(true);
        }
        if (pass_rep.value == ''){
            alert('Chybí vypln\u011bné heslo pro kontrolu!');
            return(true);
        }
        if (pass_rep.value != pass.value){
            alert('Nová hesla nejsou stejná!!');
            return(true);
        }
        return(true);
    }
</script>
    <?php
}
}
?>
